//体检条码
function designAndPrintData(LODOP, config) {
	LODOP.PRINT_INIT("");//必须打印初始化一下  
	LODOP.SET_PRINT_PAGESIZE(1, 500, 400, "");////设定打印页面大小：宽度、高度固定
	//LODOP.SET_PRINT_PAGESIZE(3, 50, 20, "");////设定打印页面大小：宽度固定、高度自适应
	// LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE", 1);
	var totalPages = Math.ceil(config.Detail.length / config.Config.psize);
	var i;
	for (i = 0; i < config.Detail.length; i++) {
		//LODOP.ADD_PRINT_TEXT("0mm", "0mm", "210mm", "6.61mm", config.Config.title);
		//LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);

		//LODOP.ADD_PRINT_BARCODE("0mm", "0mm", 76, 76, "QRCode", config.Detail[i].QRCode);
		LODOP.ADD_PRINT_BARCODE("1mm", "1mm", 78, 78, "QRCode", config.Detail[i].QRCode);
		//LODOP.SET_PRINT_STYLEA(0, "GroundColor", "#0080FF");
		LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 5);//设置二维码版本为5

		LODOP.ADD_PRINT_TEXT("1mm", "22mm", "14mm", "4mm", "口腔□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("1mm", "38mm", "14mm", "4mm", "视力□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("5mm", "22mm", "25mm", "4mm", "电脑验光□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("9mm", "22mm", "25mm", "4mm", "内、外科□");
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		LODOP.ADD_PRINT_TEXT("13mm", "22mm", "25mm", "4mm", "身高体重□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("17mm", "22mm", "25mm", "4mm", "血压心率□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("21.2mm", "0mm", "50mm", "4.21mm", config.Detail[i].Title);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		LODOP.ADD_PRINT_TEXT("25mm", "0mm", "50mm", "4.21mm", config.Detail[i].IDCardNo);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		//LODOP.ADD_PRINT_BARCODE("4.3mm", "18mm", 100, 32, "Codabar", config.Detail[i].Code);
		LODOP.ADD_PRINT_BARCODE("28.5mm", "1.4mm", 182, 30, "Codabar", config.Detail[i].ID);
		//LODOP.ADD_PRINT_BARCODE("4mm", "21mm", 120, 28, "EAN128C", config.Detail[i].ID);
		LODOP.SET_PRINT_STYLEA(0, "ShowBarText", 0);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		LODOP.ADD_PRINT_TEXT("37mm", "0mm", "50mm", "4.21mm", "编号：" + config.Detail[i].ID);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		LODOP.NEWPAGE();
	}
}

function printData(LODOP, config) {
	// LODOP.SET_PRINT_MODE("PRINT_NOCOLLATE", 1);
	var totalPages = Math.ceil(config.Detail.length / config.Config.psize);
	var i;
	for (i = 0; i < config.Detail.length; i++) {
		if ((i + 1) % 20 === 1) {
			LODOP.PRINT_INIT("体检条码打印_" + new Date().getTime());//必须打印初始化一下  
			LODOP.SET_PRINT_PAGESIZE(1, 500, 400, "");////设定打印页面大小：宽度、高度固定
			//LODOP.SET_PRINT_PAGESIZE(3, 50, 20, "");////设定打印页面大小：宽度固定、高度自适应
		}
		//LODOP.ADD_PRINT_TEXT("0mm", "0mm", "210mm", "6.61mm", config.Config.title);
		//LODOP.SET_PRINT_STYLEA(0, "ItemType", 1);

		//LODOP.ADD_PRINT_BARCODE("0mm", "0mm", 76, 76, "QRCode", config.Detail[i].QRCode);
		LODOP.ADD_PRINT_BARCODE("1mm", "1mm", 78, 78, "QRCode", config.Detail[i].QRCode);
		//LODOP.SET_PRINT_STYLEA(0, "GroundColor", "#0080FF");
		LODOP.SET_PRINT_STYLEA(0, "QRCodeVersion", 5);//设置二维码版本为5

		LODOP.ADD_PRINT_TEXT("1mm", "22mm", "14mm", "4mm", "口腔□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("1mm", "38mm", "14mm", "4mm", "视力□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("5mm", "22mm", "25mm", "4mm", "电脑验光□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("9mm", "22mm", "25mm", "4mm", "内、外科□");
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		LODOP.ADD_PRINT_TEXT("13mm", "22mm", "25mm", "4mm", "身高体重□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("17mm", "22mm", "25mm", "4mm", "血压心率□");
		//LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
		//LODOP.SET_PRINT_STYLEA(0, "FontSize", 13);

		LODOP.ADD_PRINT_TEXT("21.2mm", "0mm", "50mm", "4.21mm", config.Detail[i].Title);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		LODOP.ADD_PRINT_TEXT("25mm", "0mm", "50mm", "4.21mm", config.Detail[i].IDCardNo);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		//LODOP.ADD_PRINT_BARCODE("4.3mm", "18mm", 100, 32, "Codabar", config.Detail[i].Code);
		LODOP.ADD_PRINT_BARCODE("28.5mm", "1.4mm", 182, 30, "Codabar", config.Detail[i].ID);
		//LODOP.ADD_PRINT_BARCODE("4mm", "21mm", 120, 28, "EAN128C", config.Detail[i].ID);
		LODOP.SET_PRINT_STYLEA(0, "ShowBarText", 0);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		LODOP.ADD_PRINT_TEXT("37mm", "0mm", "50mm", "4.21mm", "编号：" + config.Detail[i].ID);
		LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);

		LODOP.NEWPAGE();

		if ((i + 1) % 20 === 0 || i + 1 === config.Detail.length) {
			LODOP.SET_PRINT_MODE("CUSTOM_TASK_NAME", "体检条码打印" + Math.ceil((i + 1) / 20));//为每个打印单独设置任务名	
			LODOP.PRINT();
		}
	}
}

function printInit(printTplConfig, tplData, action) {
	if (!printTplConfig.SvrHost) {
		printTplConfig.SvrHost = "http://localhost:8000";
	}
	jQuery.ajax({
		url: printTplConfig.SvrHost + (printTplConfig.SvrHost.substr(-1) === "/" ? "" : "/") + "CLodopfuncs.js?priority=" + new Date().getTime(),
		dataType: "script",
		success: function (resp) {
			setTimeout(function () {
				var LODOP;
				try {
					LODOP = getCLodop();
					if (!LODOP) {
						layer && layer.open({
							type: 1,
							title: false,
							closeBtn: 0,
							shadeClose: true,
							content: "<font color='#FF00FF'>Web打印服务CLodop未安装启动，点击<a href='CLodop_Setup_for_Win32NT.exe' target='_blank'>这里</a>下载安装（若已安装过，可点击<a href='CLodop.protocol:setup' target='_self'>这里</a>直接启动），成功后请刷新本页面。</font>"
						});
						return;
					}
					console.log('LODOP.CVERSION:', LODOP.CVERSION);
					if (LODOP.CVERSION < "3.0.8.3") {
						layer && layer.open({
							type: 1,
							title: false,
							closeBtn: 0,
							shadeClose: true,
							content: "<br><font color='#FF00FF'>Web打印服务CLodop需升级!点击<a href='CLodop_Setup_for_Win32NT.exe' target='_blank'>这里</a>执行升级,升级成功后请刷新本页面。</font>"
						});
					}
					//===如下空白位置适合调用统一功能(如注册语句、语言选择等):==
					LODOP.SET_LICENSES("杭州感知科技有限公司", "89600FD5AB0D66747807D05CE0721A65", "", "");
					//=======================================================
				} catch (err) {
					alert("打印控件初始化失败:" + err);
				}
				var printConfig = {};
				var i;
				var prefixStr = "0000000000";
				for (i = 0; i < tplData.length; i++) {
					tplData[i].Title = tplData[i].SName + "-" + tplData[i].GName + tplData[i].CName;
					tplData[i].ID = (prefixStr + tplData[i].ID).substr(tplData[i].ID.toString().length, prefixStr.length);
					//tplData[i].QRCode = "http://tj.sqcdrj.com/m/#/exam/2019/e3/" + tplData[i].ID;
					tplData[i].QRCode = tplData[i].ID;
				}
				printConfig.Detail = tplData;
				printConfig.Config = { title: printTplConfig.Title, psize: printTplConfig.PageSize, phone: printTplConfig.Phone, address: printTplConfig.DetailAddress };
				switch (action) {
					case "DESIGN":
						{
							designAndPrintData(LODOP, printConfig);
							LODOP.PRINT_DESIGN(); //打印设计
						}
						break;
					case "SETUP":
						{
							designAndPrintData(LODOP, printConfig);
							LODOP.PRINT_SETUP(); //打印维护
						}
						break;
					case "PREVIEW":
						{
							designAndPrintData(LODOP, printConfig);
							LODOP.PREVIEW(); //打印预览
						}
						break;
					default:
						{
							printData(LODOP, printConfig);//直接打印
						}
						break;
				}
				// LODOP.SET_PREVIEW_WINDOW(0, 0, 0,1024 , 700, "预览查看.开始打印");
				// LODOP.SET_SHOW_MODE("LANDSCAPE_DEFROTATED", 1);//横向时的正向显示
				// LODOP.SET_SHOW_MODE("SETUP_ENABLESS", 11111111000001);
			}, 100);
		},
		error: function (xhr, err, ex) {
			alert("连接打印服务器失败:" + err);
		}
	});
}